package com.boyaa.shells.tool 
{
	import com.boyaa.shells.GlobalConfig;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	/**
	 * 
	 * @author ddc
	 */
	public class TextTip 
	{
		
		private var _tipText:TextField = null;
		private var _bgShape:Sprite = null;
		private var _point:Point = null;
		private var _str:String = "";
		private var _height:Number = 0;
		private var _width:Number = 0;
		
		public function TextTip() 
		{
			
		}
		
		public function showTip(point:Point, str:String):void 
		{
			_point = point;
			_str = str;
			//初始化动态文本
			_tipText = new TextField();
			_tipText.text = _str;
			_tipText.multiline = false;
			_tipText.wordWrap = false;
			_tipText.autoSize = GlobalConfig.lanVersion == 5 ? TextFieldAutoSize.RIGHT : TextFieldAutoSize.CENTER;
			_tipText.x = _point.x + 16;	
			_tipText.y = _point.y - 24;
			//设置动态文本样式
			var format:TextFormat = new TextFormat();
			format.font = GlobalConfig.lanVersion == 5 ? "Arial" : "_sans";
			format.leftMargin = 4;
			format.rightMargin = 4;
			format.size = 12;
			_tipText.setTextFormat(format);
			// 绘制文本框背景
			_height = _tipText.height + 8;
			_width = _tipText.textWidth + 14;
			_bgShape = new Sprite();
			_bgShape.graphics.beginFill(0xffffff);
			_bgShape.graphics.drawRoundRect(_tipText.x, _tipText.y - 4, _width, _height, 10);
			_bgShape.graphics.endFill();
			//addChld至显示对象
			_bgShape.addChild(_tipText);
		}
		
		public function hideTip():void 
		{
			_tipText.text = "";
			_bgShape.parent && _bgShape.parent.removeChild(_bgShape);
			_tipText.parent && _tipText.parent.removeChild(_tipText);
			_tipText = null;
			_bgShape = null;
		}
		
		public function get bgShape():Sprite { return _bgShape; }
		
	}
}